package com.ruoyi.web.controller.vantController.teamController;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.domain.construction.RentalService;
import com.ruoyi.system.domain.customer.CustomerLogin;
import com.ruoyi.system.domain.zhuangxiumain.orderformMain.OrderDetail;
import com.ruoyi.system.domain.zhuangxiumain.orderformMain.OrderMaster;
import com.ruoyi.system.domain.zhuangxiumain.shopMain.BrandInfo;
import com.ruoyi.system.domain.zhuangxiumain.shopMain.ProductInfo;
import com.ruoyi.system.service.construction.RentalServiceService;
import com.ruoyi.system.service.vantservice.orderservice.ApiOrderDetailService;
import com.ruoyi.system.service.vantservice.orderservice.ApiOrderMasterService;
import com.ruoyi.system.service.vantservice.orderservice.ApiOrderVoucherService;
import com.ruoyi.system.service.vantservice.teamservice.ApiRentalService;
import com.ruoyi.system.utils.TokenUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@Api(value = "租赁服务接口", tags = {"租赁服务接口"})
@RestController
@RequestMapping("/api/team/rental")
@CrossOrigin
public class ApiRentalController {

    @Autowired
    private ApiRentalService apiRentalService;

    @Autowired
    private ApiOrderMasterService apiOrderMasterService;

    @Autowired
    private ApiOrderDetailService apiOrderDetailService;

    @Autowired
    private ApiOrderVoucherService apiOrderVoucherService;

    @Autowired
    private TokenUtils tokenUtils;

    @Autowired
    private HttpServletRequest request;

    /**
     * 查询租赁服务类别列表
     * @return
     */
    @ApiResponses({@ApiResponse(code = 200, message = "正常", response = BrandInfo.class)})
    @ApiOperation(value = "查询租赁服务类别列表")
    @GetMapping("/selectLeaseList")
    public AjaxResult selectLeaseList(){
        return AjaxResult.success(apiRentalService.selectLeaseList());
    }

    /**
     * 根绝类别ID查询租赁服务商品列表
     * @param teamId
     * @return
     */
    @ApiResponses({@ApiResponse(code = 200, message = "正常", response = BrandInfo.class)})
    @ApiOperation(value = "查询租赁服务商品列表")
    @GetMapping("/selectRentalServiceList/{teamId}")
    public AjaxResult selectRentalServiceList(@PathVariable(value = "teamId", required = false) Integer teamId){
        return AjaxResult.success(apiRentalService.selectRentalServiceList(teamId));
    }


    @PostMapping("/selectRentalServiceListTwo")
    public AjaxResult selectRentalServiceListTwo(@RequestBody RentalService rentalService)
    {
        rentalService.setTeamId(Integer.valueOf(rentalService.getA()));
        return AjaxResult.success(apiRentalService.selectRentalServiceListTwo(rentalService));
    }

    @GetMapping("/selectRentalServiceListOne/{address}")
    public AjaxResult selectRentalServiceListOne(@PathVariable(value = "address", required = false) String address){
        return AjaxResult.success(apiRentalService.selectRentalServiceListOne(address));
    }

    /**
     * 查询租赁服务商品信息
     * @param rentalId
     * @return
     */
    @ApiResponses({@ApiResponse(code = 200, message = "正常", response = BrandInfo.class)})
    @ApiOperation(value = "查询租赁服务商品信息")
    @GetMapping("/selectRentalServiceById/{rentalId}")
    public AjaxResult selectRentalServiceById(@PathVariable(value = "rentalId", required = false) Long rentalId){
        AjaxResult ajaxResult = AjaxResult.success();
        // 查询租赁服务商品信息
        ajaxResult.put("rentalService",apiRentalService.selectRentalServiceById(rentalId));
        // 查询租赁服务商品规格信息
        ajaxResult.put("rentalLabel",apiRentalService.selectRentalLabelByServiceId(rentalId));
        return ajaxResult;
    }

    /**
     * 订单预支付
     * @param orderMaster
     * @return
     */
    @PostMapping("/insertOrderMaster")
    public AjaxResult insertOrderMaster(@RequestBody OrderMaster orderMaster){
        // 获取前台登录用户信息
        CustomerLogin customerLogin = tokenUtils.getLoginCustomer(request);
        orderMaster.setCustomerId(customerLogin.getCustomerId().intValue());
        orderMaster.setCustomerPhone(customerLogin.getLoginName());
        apiOrderMasterService.insertOrderMaster(orderMaster);
        return AjaxResult.success(orderMaster.getOrderId());
    }

    /**
     * 订单详情
     * @param orderDetail
     * @return
     */
    @PostMapping("/insertOrderDetail")
    public AjaxResult insertOrderDetail(@RequestBody OrderDetail orderDetail){
        return AjaxResult.success(apiOrderDetailService.insertOrderDetail(orderDetail));
    }
}
